﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FacebookWrapper.ObjectModel;
using FacebookWrapper;

namespace B13_Ex03_David_300512340_Alexey_321203689
{
    public class UserWrapper
    {
        public User UserInformation { get; set; }

        public override string ToString()
        {
            return UserInformation.Name;
        }

        public string ProfilePicture
        {
            get { return UserInformation.PictureNormalURL; }
        }

        public List<UserWrapper> GetFriendsList()
        {
            List<UserWrapper> friendsList = new List<UserWrapper>();

            if (UserInformation != null)
            {
                try
                {
                    foreach (User friend in UserInformation.Friends)
                    {
                        friendsList.Add(new UserWrapper() { UserInformation = friend });
                    }
                }
                catch (Exception e)
                {
                    string msg = string.Format("Error fetching friends!");
                    throw new Exception(msg, e);
                }
            }

            return friendsList;
        }

        public List<Event> GetEventsList()
        {
            List<Event> eventsList = new List<Event>();

            if (UserInformation != null)
            {
                try
                {
                    foreach (Event oneEvent in UserInformation.Events)
                    {
                        eventsList.Add(oneEvent);
                    }
                }
                catch (Exception e)
                {
                    string msg = string.Format("Error fetching events!");
                    throw new Exception(msg, e);
                }
            }

            return eventsList;
        }

        public List<AlbumWrapper> GetAlbumsList()
        {
            List<AlbumWrapper> albumsList = new List<AlbumWrapper>();

            if (UserInformation != null)
            {
                try
                {
                    foreach (Album album in UserInformation.Albums)
                    {
                        albumsList.Add(new AlbumWrapper() { AlbumInformation = album });
                    }
                }
                catch (Exception e)
                {
                    string msg = string.Format("Error fetching albums!");
                    throw new Exception(msg, e);
                }
            }

            return albumsList;
        }

        public List<FeedWrapper> GetFeedsList()
        {
            List<FeedWrapper> feedsList = new List<FeedWrapper>();

            if (UserInformation != null)
            {
                try
                {
                    foreach (Post feed in UserInformation.NewsFeed)
                    {
                        if (feed.Message != null)
                        {
                            feedsList.Add(new FeedWrapper() { Feed = feed });
                        }
                    }
                }
                catch (Exception e)
                {
                    string msg = string.Format("Error fetching feeds!");
                    throw new Exception(msg, e);
                }
            }

            return feedsList;
        }
    }
}
